<template>
  <el-dialog v-model="dialogVisible" :title="dialogProps.title" width="70%" lock-scroll destroy-on-close draggable>
    <pro-table ref="proTableRef" row-key="id" :columns="columns" :request-api="getLogByJobPageApi" :init-param="initParam">
    </pro-table>
  </el-dialog>
</template>

<script setup lang="ts" name="JobLogDialog">
import type { ProTableInstance, ColumnProps } from "@/components/ProTable/interface";
import { ref, computed } from "vue";
import { getLogByJobPageApi } from "@/api/modules/system/logByJob";
import ProTable from "@/components/ProTable/index.vue";

interface DialogProps {
  title: string;
  isView: boolean;
  param: {
    jobId: string;
  };
}

/** 表格实例 */
const proTableRef = ref<ProTableInstance>();
/** 弹窗是否可见 */
const dialogVisible = ref(false);
/** 弹窗属性 */
const dialogProps = ref<DialogProps>({
  isView: false,
  title: "",
  param: { jobId: "" }
});
/** 表单初始化参数 */
const initParam = computed(() => dialogProps.value.param);
/** 表格配置项 */
const columns: ColumnProps[] = [
  { prop: "triggerId", label: "触发器Id", align: "left" },
  { prop: "lastRunTime", label: "最近运行时间", align: "left" },
  { prop: "nextRunTime", label: "下一次运行时间", align: "left" },
  { prop: "result", label: "本次执行结果", align: "left" },
  {
    prop: "status",
    label: "状态",
    width: 150,
    tag: true,
    enum: [
      { label: "积压", value: 0, tagType: "danger" },
      { label: "就绪", value: 1, tagType: "success" },
      { label: "正在运行", value: 2, tagType: "primary" },
      { label: "暂停", value: 3, tagType: "info" },
      { label: "阻塞", value: 4, tagType: "danger" },
      { label: "由失败进入就绪", value: 5, tagType: "warning" },
      { label: "归档", value: 6, tagType: "info" },
      { label: "崩溃", value: 7, tagType: "danger" },
      { label: "超限", value: 8, tagType: "danger" },
      { label: "无触发时间", value: 9, tagType: "info" },
      { label: "未启动", value: 10, tagType: "info" },
      { label: "未知触发器", value: 11, tagType: "info" },
      { label: "未知程序", value: 12, tagType: "info" }
    ]
  },
  { prop: "elapsedTime", label: "耗时(毫秒)", width: 150 }
];

// 接收父组件传过来的参数
const acceptParams = (params: DialogProps) => {
  dialogProps.value = params;
  dialogVisible.value = true;
};

defineExpose({
  acceptParams
});
</script>

<style lang="scss">
.table-expand {
  padding: 0 8px;
  .expand-col {
    min-width: 180px;
  }
}
</style>
